<?php
// +----------------------------------------------------------------------

// +----------------------------------------------------------------------

namespace Home\Model;
use Think\Model;

/**
 * 文档基础模型
 */
class CollectionModel extends Model{

    protected $_validate = array(
    );

    public function collectionAdd($data){     
        $data['date_added'] =  date('y-m-d h:i:s',time());
        $collectiondata = $this
        ->data($data)
        ->add();
        return $collectiondata; 
    }

    public function collectionGet($uid){
        $data = $this->getCollection($uid);
        if($data){
            $result['success'] = true;
            foreach ($data as $key => $value) {
                $result['info'][] = $value['article_id'];
            }
        }else{
            $result['success'] = fasle;
            $result['error'] = '收藏夹为空';
        }
        return $result;
    }

    public function checkCollectionIsHave($data){
        $collectiondata = $this
        ->where($data)
        ->find();
        return $collectiondata;
    } 

    protected function getCollection($uid){
        $where['uid'] = $uid;
        $where['status'] = 1;
        $collectiondata = $this
        ->where($where)
        ->field('article_id')
        ->select();
        return $collectiondata;
    }
}
